package com.sfx.concurrent.demo.OtherCoding;

import java.util.LinkedList;
import java.util.Queue;

class MyStack {
    private Queue<Integer> queueIn;
    private Queue<Integer> queueOut;
    public MyStack() {
        queueIn = new LinkedList<>();
        queueOut = new LinkedList<>();
    }
    
    public void push(int x) {
        queueIn.offer(x);
    }
    private void dumpQueueIn() {
        if(queueOut.isEmpty()) {
            while(!queueIn.isEmpty()) {
                queueOut.offer(queueIn.poll());
            }
        }


    }
    public int pop() {
        dumpQueueIn();
        return queueOut.poll();
    }
    
    public int top() {
        dumpQueueIn();
        return queueOut.peek();
    }
    
    public boolean empty() {
        return queueIn.isEmpty() && queueOut.isEmpty();
    }
}